<!DOCTYPE html>
<html lang="en"><!-- InstanceBegin template="/Templates/MainTemplate.dwt" codeOutsideHTMLIsLocked="false" -->
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="">
<!-- #BeginEditable "doctitle" -->
<title>Struts Jdon JDBC Application</title>  
<!-- #EndEditable -->
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
.STYLE3 {	color: #0000FF;
	font-weight: bold;
}
</style>
<!-- InstanceEndEditable -->
    <!-- Bootstrap core CSS -->
     <link rel="stylesheet" href="css/bootstrap.min.css">   

    <!-- Custom styles for this template -->
    <link href="css/starter-template.css" rel="stylesheet">

   <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
    <![endif]-->    
  </head>
<body>
 <div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="index.html">Jdon Framework</a>
        </div>
        <div class="collapse navbar-collapse">
          <ul class="nav navbar-nav">
                <li class="active"><a href="index.html">Home</a></li>
               <li><a href="https://sourceforge.net/projects/jdon/files/">Download</a></li>
               <li><a href="doc.htm" >Document</a></li>
               <li><a href="quickconf.html">Qucik Start</a> </li>
               <li><a href="examples.html">Examples</a></li>
               <li ><a href="https://github.com/banq/jdonframework">Github</a></li>
               <li><a href="articles.html">Articles</a></li>
          </ul>
        </div><!--/.nav-collapse -->
      </div>
    </div>
    

    <div class="container">
     <div class="starter-template">     
    
 <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">  
  <tr>     
    <td bgcolor="#FFFFFF"  valign="top" align="left">

                  
				<!-- #BeginEditable "main" --> 
                  <p>　　</p>
                  <h1> Struts Jdon JDBC Application</h1>
                  <p>We use a simple &quot;UserModel&quot; application to show how JdonFramework work in a web application, online demo: <a href="http://www.jdon.com/testWeb/" target="_blank">http://www.jdon.com/testWeb/</a>. in this sample, we show how to Create/Read/Update/Delete(CRUD) the UserModel, include pageinate the UserModel collection. This sample source is included in <a href="https://jdon.dev.java.net/servlets/ProjectDocumentList?folderID=9620&expandFolder=9620&folderID=0" target="_blank">JdonFramework source package</a>. </p>
                  <h2>Domain Model</h2>
                  <p>At first, By Evans DDD, we can get a domain Model: UserModel:</p>
                  <p>&nbsp;</p>
                  <table width="600" border="0">
                    <tr>
                      <td bgcolor="#CCCCCC"><p>&nbsp;</p>
                        <p>@Model<br />
                          public class UserModel {</p>
                        <p> &nbsp; &nbsp;&nbsp; private String userId;<br />
                          &nbsp; &nbsp;&nbsp; private String name;</p>
                        <p>&nbsp; &nbsp;&nbsp;  @Inject<br />
                          &nbsp; &nbsp;&nbsp; private ComputerRole computerRole;</p>
                        <p>&nbsp;</p>
                        <p>&nbsp;</p></td>
                    </tr>
                  </table>
                  <p>Two: Role. Domain event producer is a Role of DCI，it includes the interactions of DCI. </p>
                  <table width="600" border="0">
                    <tr>
                      <td bgcolor="#CCCCCC"><p>&nbsp;</p>
                        <p>@Introduce(&quot;message&quot;)<br />
                          public class ComputerRole {</p>
                        <p> &nbsp; &nbsp;&nbsp; @Send(&quot;computeCount&quot;)<br />
                          &nbsp; &nbsp;&nbsp; public DomainMessage computeCount(UserModel user) {<br />
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; return new DomainMessage(user);<br />
                          &nbsp; &nbsp;&nbsp; }</p>
                        <p> &nbsp; &nbsp;&nbsp; @Send(&quot;saveUser&quot;)<br />
                          &nbsp; &nbsp;&nbsp; public DomainMessage save(UserModel user) {<br />
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; return new DomainMessage(user);<br />
                          &nbsp; &nbsp;&nbsp; }</p>
                        <p>}</p>
                        <p>&nbsp;</p></td>
                    </tr>
                  </table>
                  <p>Three: Context, In Context,The Role will be injected into the data.</p>
                  <table width="600" border="0">
                    <tr>
                      <td bgcolor="#CCCCCC"><p>public class ComputeContext {</p>
                        <p> &nbsp; &nbsp;&nbsp;private DomainMessage ageAsyncResult;</p>
                        <p> &nbsp; &nbsp;&nbsp; public void preloadData(UserModel user) {<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; if (ageAsyncResult == null)<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; ageAsyncResult = user.getUserDomainEvents().computeCount(user);<br>
                          &nbsp; &nbsp;&nbsp; }</p>
                        <p> &nbsp; &nbsp;&nbsp; public int loadCountNow(UserModel user) {<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; preloadData(user);<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; return (Integer) ageAsyncResult.getEventResult();<br>
                          &nbsp; &nbsp;&nbsp; }</p>
                        <p> &nbsp; &nbsp;&nbsp; public int loadCountByAsync(UserModel user) {<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; if (ageAsyncResult == null)<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; ageAsyncResult = user.getUserDomainEvents().computeCount(user);<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; else if (ageAsyncResult != null)<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; return (Integer) ageAsyncResult.getEventResult();<br>
                          &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; return -1;</p>
                        <p> &nbsp; &nbsp;&nbsp;}</p>
                        <p>}<br>
                        </p>
                        <p>&nbsp;</p></td>
                    </tr>
                  </table>
                  <p>above all source in: <a href="http://code.google.com/p/jivejdon/downloads/detail?name=SimpleJdonFrameworkTest.rar&amp;can=2&amp;q=">SimpleJdonFrameworkTest.rar</a></p>
                  <h2>JSP Web Pages</h2>
                  <p><strong>user.jsp</strong>: For CRUD operations, we only create one jsp named user.jsp, in this jsp, by &quot;action&quot; value, we can finish CRUD operations.</p>
                  <p>&nbsp;</p>
                  <table width="500" border="0" bordercolor="#CCCCCC">
                    <tr>
                      <td bgcolor="#CCCCCC"><p>user.jsp (include all CRUD in one Jsp):</p>
                        <p><br>
                          &lt;html:form action=&quot;/userSaveAction.do&quot; method=&quot;POST&quot; onsubmit=&quot;return checkPost();&quot;&gt;<br>
                          &nbsp;&nbsp;&nbsp;<strong>&lt;html:hidden property=&quot;action&quot;/&gt;</strong></p>
                        <p>&nbsp;&nbsp;&nbsp;UserId:&lt;html:text property=&quot;userId&quot;/&gt;<br>
                          &nbsp;&nbsp;&nbsp;&lt;br&gt;<br>
                          &nbsp;&nbsp;&nbsp;Name:&lt;html:text property=&quot;name&quot;/&gt;<br>
                          &nbsp;&nbsp;&nbsp;&lt;br&gt;<br>
                          &nbsp;&nbsp;&nbsp;&lt;html:submit property=&quot;submit&quot; value=&quot;Submit&quot;/&gt;<br>
                          &lt;/html:form&gt;</p>
                        <p>&nbsp;</p></td>
                    </tr>
                  </table>
                  <p>&nbsp;</p>
                  <p><img src="images/crud.gif" alt="crud" width="500" height="140"></p>
                  <p>&nbsp;</p>
                  <p><strong>userList.jsp: </strong>List all UserModels collection and auto paginate them. </p>
                  <table width="500" border="0" bgcolor="#CCCCCC">
                    <tr>
                      <td><p>&lt;logic:iterate indexId=&quot;i&quot;   id=&quot;user&quot; name=&quot;listForm&quot; property=&quot;list&quot; &gt;<br>
                      </p>
                        <p>&lt;bean:write name=&quot;user&quot; property=&quot;userId&quot; /&gt;<br>
                          &lt;bean:write name=&quot;user&quot; property=&quot;name&quot; /&gt;<br>
                          <br>
                          &lt;input type=&quot;radio&quot; name=&quot;userId&quot; value=&quot;&lt;bean:write name=&quot;user&quot; property=&quot;userId&quot; /&gt;&quot;&gt; </p>
                        <p>&lt;/logic:iterate&gt;</p>
                        <p>&lt;html:link page=&quot;/userAction.do&quot;&gt;Add&lt;/html:link&gt;</p>
                        <p>....</p>
                        <p>&lt;!-- Auto Pagination taglib of jdon --&gt; <br>
                          &lt;MultiPages:pager actionFormName=&quot;listForm&quot; page=&quot;/userListAction.do&quot;&gt;</p>
                        <p>&lt;MultiPages:prev name=&quot;[Prev ]&quot; /&gt;<br>
                          &lt;MultiPages:index displayCount=&quot;1&quot; /&gt;<br>
                          &lt;MultiPages:next  name=&quot;[Next ]&quot; /&gt;<br>
                          &lt;/MultiPages:pager&gt;</p>
                        <p><br>
                        </p></td>
                    </tr>
                  </table>
                  <p>&nbsp;</p>
                  <p><img src="images/userList.gif" alt="userlist" width="631" height="509"></p>
                  <h2>Business Service </h2>
                  <p>In Business Layer, we have a interface named TestService, it has CRUD operation about UserModel packed in EventModel, if any errors happened you can pass the error infos into it and display the error infos to JSP Webpages. </p>
                  <table width="500" border="0" bgcolor="#CCCCCC">
                    <tr>
                      <td><p>public interface TestService {<br>
                        <br>
                        public void <span class="STYLE3">createUser</span>(EventModel em);<br>
                        public void <span class="STYLE3">updateUser</span>(EventModel em);<br>
                        public void <span class="STYLE3">deleteUser</span>(EventModel em);<br>
                        public UserModel <span class="STYLE3">getUser</span>(String userId);</p>
                        <p> /**<br>
                          * for batch inquiry <br>
                          */<br>
                          public PageIterator getAllUsers(int start, int count);<br>
                          <br>
                          /**<br>
                          * for the command pattern of service invoke <br>
                          */<br>
                          public void xxxxx(EventModel em);<br>
                          <br>
                          <br>
                          }</p></td>
                    </tr>
                  </table>
                  <p><strong>No Controllers</strong>: In this sample.there is no any controlles of MVC, no CRUD controller actions of Struts, the JSP directly send commands to TestService, to do these only need jdonframework.xml configuration as below:</p>
                  <img src="images/mapping.gif" alt="mapping" width="670" height="342">
                  <h2>Packaging </h2>
                  <p>run Ant's build.xml (you maybe modify the  deploy.dir value in build.xml) , after packaging, you get a deploy file testWeb.war under dist directory. </p>
                  <p><img src="images/package.gif" alt="pack" width="816" height="377"></p>
                  <h2>The DataBase</h2>
                  <p>Creating the Database Schema, import database.sql into your database: </p>
                  <table width="500" border="0" bgcolor="#CCCCCC">
                    <tr>
                      <td><p>use test;<br>
                        create table testuser (<br>
                        userId           char(20) not null,<br>
                        name             varchar(20) null,<br>
                        PRIMARY KEY  (userId)<br>
                        );<br>
                        INSERT INTO testuser VALUES ('1', 'tony');<br>
                        INSERT INTO testuser VALUES ('2', 'sunny');<br>
                        INSERT INTO testuser VALUES ('3', 'kevin');</p>
                        <p></p></td>
                    </tr>
                  </table>
                  <h2>Deploying the Application</h2>
                  <p>copy dits/testWeb.war to tomcat's webapps, start tomcat, after see the infos as below, run this appalication in browser: http://127.0.0.1:8080/testWeb/ </p>
                  <p><img src="images/deploy.gif" alt="deploy" width="647" height="422"></p>
                  <p>&nbsp;</p>
                  <h3><a href="jdonMovie.htm">Struts + Jdon + Hibernate video</a></h3>
                  <p>&nbsp;</p>
                  <!-- #EndEditable -->
                 
			  	
          </td>
		  <td width="340" valign="top"  bgcolor="#FFFFD7"> 
          <div class="adsensf" id="vgad336x280">
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- 页上左336 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:336px;height:280px"
     data-ad-client="ca-pub-7573657117119544"
     data-ad-slot="6751585519"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</div>         
 </td>
  </tr>
</table>


<table width="100%" border="0" cellspacing="0" cellpadding="0" height="2" bgcolor="#000000"  align="center">
              <tr>
                <td></td>
              </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
<tr><td height="20" bgcolor="#CAC9BB" align="center">
  
  </td>
</tr>
</table>
 </div>
</div><!-- /.container -->

<!-- InstanceBeginEditable name="EditRegion3" --><!-- InstanceEndEditable -->
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
<!-- AddThis Smart Layers BEGIN -->
<!-- Go to http://www.addthis.com/get/smart-layers to customize -->
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-52c4b79515624135"></script>
<script type="text/javascript">
  addthis.layers({
    'theme' : 'transparent',
    'share' : {
      'position' : 'left',
      'numPreferredServices' : 5
    },  
    'whatsnext' : {},  
    'recommended' : {} 
  });
</script>
<!-- AddThis Smart Layers END -->    
</body>
<!-- InstanceEnd --></html>
